package pers.xhh.shopapi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.xhh.shopapi.annotation.UserLoginToken;
import pers.xhh.shopapi.common.Mi;
import pers.xhh.shopapi.service.MiOrderService;

/**
 * @author wei-xhh
 * @date 2020-11-27
 */
@CrossOrigin
@RestController
@RequestMapping("/api/v1")
public class MiOrderController {

    @Autowired
    MiOrderService miOrderService;

    @UserLoginToken
    @GetMapping("/orders")
    public Mi orders(@RequestParam(required = false) Integer pagenum,
                      @RequestParam(required = false) Integer pagesize){
        return miOrderService.allOrder(pagenum, pagesize);
    }

    @UserLoginToken
    @DeleteMapping("/order/{orderId}")
    public Mi cancelOrder(@PathVariable("orderId") Integer orderId){
        return miOrderService.cancelOrder(orderId);
    }

    @UserLoginToken
    @PostMapping("/order/{orderId}/status/{status}")
    public Mi updateOrderStatus(@PathVariable("orderId") Integer orderId,
                          @PathVariable("status") Integer status){
        return miOrderService.updateOrderStatus(orderId, status);
    }
}
